package com.magic.uschat.adapter;

import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.TextView;

import com.amap.api.maps.AMap.InfoWindowAdapter;
import com.amap.api.maps.model.Marker;
import com.magic.uschat.R;
import com.magic.uschat.bean.LocationMarkerData;

public class CustomMarkerInfoWindowAdapter implements InfoWindowAdapter {
	private Context context;
	private LayoutInflater layoutInflater;
	public CustomMarkerInfoWindowAdapter(Context context) {
		super();
		this.context = context;
		layoutInflater = LayoutInflater.from(context);
	}

	@Override
	public View getInfoContents(Marker marker) {
		View view = layoutInflater.inflate(R.layout.location_navi_info_window, null);
		TextView tv_address = (TextView) view.findViewById(R.id.tv_navi_address);
		TextView tv_go = (TextView) view.findViewById(R.id.tv_navi);
		Object data = marker.getObject();
		if (data instanceof LocationMarkerData) {
			final LocationMarkerData lds = (LocationMarkerData)data;
			tv_address.setText(lds.address);
			tv_go.setOnClickListener(new OnClickListener() {
				@Override
				public void onClick(View v) {
					Uri uri = Uri.parse("geo:"+lds.latlng.latitude+","+lds.latlng.longitude);
					Intent intent = new Intent(Intent.ACTION_VIEW,uri);
					context.startActivity(intent);
				}
			});
		}
		return view;
	}

	@Override
	public View getInfoWindow(Marker marker) {
		return null;
	}

}
